#include <rpcFw\CodecInf.h>
#include <rpcFw\JsonCodec.h>

DServerInf::DServerInf():
m_pJsonCodec(new DJsonCodec)
{

}

DServerInf::~DServerInf()
{

}

EnHandleResult DServerInf::OnPrepareListen(ITcpServer* pSender, SOCKET soListen)
{
	return EnHandleResult::HR_OK;
}

EnHandleResult DServerInf::OnAccept(ITcpServer* pSender, CONNID dwConnID, UINT_PTR soClient)
{
	m_RecvPacket[dwConnID] = PacketStruct();

	return EnHandleResult::HR_OK;
}

EnHandleResult DServerInf::OnHandShake(ITcpServer* pSender, CONNID dwConnID)
{
	return EnHandleResult::HR_OK;
}

EnHandleResult DServerInf::OnReceive(ITcpServer* pSender, CONNID dwConnID, const BYTE* pData, int iLength)
{
	m_pJsonCodec->decodeData(m_RecvPacket[dwConnID], dwConnID, pData, iLength);
	return EnHandleResult::HR_OK;
}

EnHandleResult DServerInf::OnSend(ITcpServer* pSender, CONNID dwConnID, const BYTE* pData, int iLength)
{
	return __super::OnSend(pSender, dwConnID, pData, iLength);
}

EnHandleResult DServerInf::OnClose(ITcpServer* pSender, CONNID dwConnID, EnSocketOperation enOperation, int iErrorCode)
{
	auto &iter = m_RecvPacket[dwConnID];
	m_RecvPacket.erase(dwConnID);

	return EnHandleResult::HR_OK;
}

EnHandleResult DServerInf::OnShutdown(ITcpServer* pSender)
{
	return __super::OnShutdown(pSender);
}

EnHandleResult DClientInf::OnHandShake(ITcpClient* pSender, CONNID dwConnID)
{
	return EnHandleResult::HR_OK;
}

EnHandleResult DClientInf::OnReceive(ITcpClient* pSender, CONNID dwConnID, const BYTE* pData, int iLength)
{
	m_pJsonCodec->decodeData(m_packetStruct, dwConnID, pData, iLength);
	return EnHandleResult::HR_OK;
}

EnHandleResult DClientInf::OnSend(ITcpClient* pSender, CONNID dwConnID, const BYTE* pData, int iLength)
{
	return EnHandleResult::HR_OK;
}

EnHandleResult DClientInf::OnClose(ITcpClient* pSender, CONNID dwConnID, EnSocketOperation enOperation, int iErrorCode)
{
	return EnHandleResult::HR_OK;
}

DClientInf::DClientInf():
m_pJsonCodec(new DJsonCodec)
{

}

DClientInf::~DClientInf()
{

}